class Solution2 {
    public boolean hasCycle(ListNode head) {
        if (head==null){
            return false;
        } else if (head.next==null){
            return false;
        }

        ListNode slow=head;
        ListNode fast=head.next;

        while(fast!=slow){
            if(fast.next==null||fast.next.next==null){
                return false;
            }
            slow=slow.next;
            fast=fast.next.next;
        }

        return true;
    }
}

public class Text4 {
}
